import instance from "../utils/request";

export async function createPlanAttraction(PlanAttraction){
    try {
        const res = await instance({
            url: '/PlanAttraction/create',
            method: 'post',
            data: PlanAttraction
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function updatePlanAttraction(planAttractionId, PlanAttraction){
    try {
        const res = await instance({
            url: '/PlanAttraction/update',
            method: 'put',
            params: {
                planAttractionId: planAttractionId
            },
            data: PlanAttraction
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function deletePlanAttraction(planAttractionId){
    try {
        const res = await instance({
            url: `/PlanAttraction/delete/${planAttractionId}`,
            method: 'delete'
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function getPlanAttraction(planAttractionId){
    try {
        const res = await instance({
            url: `/PlanAttraction/detail/${planAttractionId}`,
            method: 'get'
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function getPlanAttractionListByPlanId(planId, pageNumber, pageSize){
    try {
        const res = await instance({
            url: `/PlanAttraction/list/${planId}`,
            method: 'get',
            params: {
                pageNumber: pageNumber,
                pageSize: pageSize
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function deletePlanAttractionListByPlanId(planId){
    try {
        const res = await instance({
            url: `/PlanAttraction/delete/plan/${planId}`,
            method: 'delete',
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function changeVisitOrder(planAttractionId, newVisitOrder){
    try {
        const res = await instance({
            url: `/PlanAttraction/change-visit-order/${planAttractionId}`,
            method: 'put',
            params: {
                newVisitOrder: newVisitOrder
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}